﻿'*******************************************************************
' Program: Data Center Visio Rack Tool
' Author: Albert E Edlund
' Date:
'
' Purpose:
'
'
'
'*******************************************************************


Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging



Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel


Imports System.Data
Imports System.IO
Imports System.Xml

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Visio



Imports visRackComponentAttributes.clsVisioSupport
Imports visRackComponentAttributes.clsDC_RackData




Public Class clsAttrDiskPhysical


#Region " Properties and definitions "

    Public m_db As Database
    Public m_ds As DataSet
    Public m_dt As DataTable

    Public m_dc As dc_DiskPhysical
    Public m_oc As Collection(Of dc_DiskPhysical)

    Private strUserId As String

    Public m_deleteCommand As DbCommand
    Public m_insertCommand As DbCommand
    Public m_updateCommand As DbCommand


    Public _clsVisio As visRackComponentAttributes.clsVisioSupport

    Public Const readAll As String = "selectTblDiskPhysical"

    ' who am I
    Private myEnum As DC_RackTables = DC_RackTables.tblAttrDiskPhysical

    '********* visio snippet vb.net vis0041vb ******************
    Private _drawingApplication As Microsoft.Office.Interop.Visio.Application
    Public Property drawingApplication() As Microsoft.Office.Interop.Visio.Application
        Get
            Return Me._drawingApplication
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Application)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("ApplicationValueIsNull", _
                    "drawingApplication is Null.")
            End If
            Me._drawingApplication = value
        End Set
    End Property

    '********* visio snippet vb.net vis0043vb ******************
    Private _drawingDocument As Microsoft.Office.Interop.Visio.Document
    Public Property drawingDocument() As Microsoft.Office.Interop.Visio.Document
        Get
            Return Me._drawingDocument
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Document)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("DocumentValueIsNull", _
                    "drawingDocument is Null.")
            End If
            Me._drawingDocument = value
        End Set
    End Property

    '********* visio snippet vb.net vis0045vb ******************
    Private _drawingWindow As Microsoft.Office.Interop.Visio.Window
    Public Property drawingWindow() As Microsoft.Office.Interop.Visio.Window
        Get
            Return Me._drawingWindow
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Window)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("WindowValueIsNull", _
                    "drawingWindow is Null.")
            End If
            Me._drawingWindow = value
        End Set
    End Property

    '********* visio snippet vb.net vis0044vb ******************
    Private _drawingPage As Microsoft.Office.Interop.Visio.Page
    Public Property drawingPage() As Microsoft.Office.Interop.Visio.Page
        Get
            Return Me._drawingPage
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Page)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("PageValueIsNull", _
                    "drawingPage is Null.")
            End If
            Me._drawingPage = value
        End Set
    End Property

    Public m_customstencilpath As String = My.Settings.path_custom_stencils
    Public Property _CustomStencilPath() As String
        Get
            Return Me.m_customstencilpath
        End Get
        Set(ByVal value As String)
            Me.m_customstencilpath = value
        End Set
    End Property


#End Region

#Region " Move/Transform Data "




    '
    ' create columns
    '
    Public Sub CreateTableColumns(ByRef tempTable As DataTable)

        Dim newDC As dc_DiskPhysical = New dc_DiskPhysical(strUserId)

        Try

            Dim colphysDiskKey As New System.Data.DataColumn
            colphysDiskKey.ColumnName = "physDiskKey"
            colphysDiskKey.DataType = GetType(Integer)
            colphysDiskKey.DefaultValue = m_dc.physDiskKey
            tempTable.Columns.Add(colphysDiskKey)

            Dim colphysDiskCompKey As New System.Data.DataColumn
            colphysDiskCompKey.ColumnName = "physDiskCompKey"
            colphysDiskCompKey.DataType = GetType(Integer)
            colphysDiskCompKey.DefaultValue = m_dc.physDiskCompKey
            tempTable.Columns.Add(colphysDiskCompKey)

            Dim colphysDiskDevIdDisk As New System.Data.DataColumn
            colphysDiskDevIdDisk.ColumnName = "physDiskDevIdDisk"
            colphysDiskDevIdDisk.DataType = GetType(String)
            colphysDiskDevIdDisk.DefaultValue = m_dc.physDiskDevIdDisk
            tempTable.Columns.Add(colphysDiskDevIdDisk)

            Dim colphysDiskDevIdPartition As New System.Data.DataColumn
            colphysDiskDevIdPartition.ColumnName = "physDiskDevIdPartition"
            colphysDiskDevIdPartition.DataType = GetType(String)
            colphysDiskDevIdPartition.DefaultValue = m_dc.physDiskDevIdPartition
            tempTable.Columns.Add(colphysDiskDevIdPartition)

            Dim colphysDiskBootable As New System.Data.DataColumn
            colphysDiskBootable.ColumnName = "physDiskBootable"
            colphysDiskBootable.DataType = GetType(String)
            colphysDiskBootable.DefaultValue = m_dc.physDiskBootable
            tempTable.Columns.Add(colphysDiskBootable)

            Dim colphysDiskSize As New System.Data.DataColumn
            colphysDiskSize.ColumnName = "physDiskSize"
            colphysDiskSize.DataType = GetType(Int64)
            colphysDiskSize.DefaultValue = m_dc.physDiskSize
            tempTable.Columns.Add(colphysDiskSize)

            Dim colphysDiskBlockSize As New System.Data.DataColumn
            colphysDiskBlockSize.ColumnName = "physDiskBlockSize"
            colphysDiskBlockSize.DataType = GetType(Integer)
            colphysDiskBlockSize.DefaultValue = m_dc.physDiskBlockSize
            tempTable.Columns.Add(colphysDiskBlockSize)

            Dim colphysDiskNumberOfBlocks As New System.Data.DataColumn
            colphysDiskNumberOfBlocks.ColumnName = "physDiskNumberOfBlocks"
            colphysDiskNumberOfBlocks.DataType = GetType(Int64)
            colphysDiskNumberOfBlocks.DefaultValue = m_dc.physDiskNumberOfBlocks
            tempTable.Columns.Add(colphysDiskNumberOfBlocks)

            Dim colphysDiskIndex As New System.Data.DataColumn
            colphysDiskIndex.ColumnName = "physDiskIndex"
            colphysDiskIndex.DataType = GetType(Integer)
            colphysDiskIndex.DefaultValue = m_dc.physDiskIndex
            tempTable.Columns.Add(colphysDiskIndex)

            Dim colphysDiskComments As New System.Data.DataColumn
            colphysDiskComments.ColumnName = "physDiskComment"
            colphysDiskComments.DataType = GetType(String)
            colphysDiskComments.DefaultValue = m_dc.physDiskComment
            tempTable.Columns.Add(colphysDiskComments)

            Dim colphysDiskLastUpdate As New System.Data.DataColumn
            colphysDiskLastUpdate.ColumnName = "physDiskLastUpdate"
            colphysDiskLastUpdate.DataType = GetType(Date)
            colphysDiskLastUpdate.DefaultValue = m_dc.physDiskLastUpdate
            tempTable.Columns.Add(colphysDiskLastUpdate)

            Dim colphysDiskLastEdit As New System.Data.DataColumn
            colphysDiskLastEdit.ColumnName = "physDiskLastEdit"
            colphysDiskLastEdit.DataType = GetType(String)
            colphysDiskLastEdit.DefaultValue = m_dc.physDiskLastEdit
            tempTable.Columns.Add(colphysDiskLastEdit)

            newDC = Nothing


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        If newDC IsNot Nothing Then
            newDC = Nothing
        End If

    End Sub



    '
    ' use for writing records
    '
    Public Sub movePropertiesToDataRow _
                (ByRef tempRow As DataRow, _
                 ByVal tempDC As dc_DiskPhysical)

        Try

            With tempDC
                tempRow.SetField("physDiskKey", .physDiskKey)
                tempRow.SetField("physDiskCompKey", .physDiskCompKey)
                tempRow.SetField("physDiskDevIdDisk", .physDiskDevIdDisk)
                tempRow.SetField("physDiskDeviIdPartition", .physDiskDevIdPartition)
                tempRow.SetField("physDiskBootable", .physDiskBootable)
                tempRow.SetField("physDiskSize", .physDiskSize)
                tempRow.SetField("physDiskBlockSize", .physDiskBlockSize)
                tempRow.SetField("physDiskNumberOfBlocks", .physDiskNumberOfBlocks)
                tempRow.SetField("physDiskIndex", .physDiskIndex)
                tempRow.SetField("physDiskComment", .physDiskComment)
                tempRow.SetField("physDiskLastUpdate", .physDiskLastUpdate)
                tempRow.SetField("physDiskLastEdit", strUserId)
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    ' for reading records
    '
    Public Sub moveDataRowToProperties _
                (ByVal tempRow As DataRow)

        Try

            With m_dc
                .initProperties()
                .physDiskKey = tempRow.Item("physDiskKey")
                .physDiskCompKey = tempRow.Item("physDiskCompKey")
                .physDiskDevIdDisk = tempRow.Item("physDiskDevIdDisk")
                .physDiskDevIdPartition = tempRow.Item("physDiskDevIdPartition")
                .physDiskBootable = tempRow.Item("physDiskBootable")
                .physDiskSize = tempRow.Item("physDiskSize")
                .physDiskBlockSize = tempRow.Item("physDiskBlockSize")
                .physDiskNumberOfBlocks = tempRow.Item("physDiskNumberOfBlocks")
                .physDiskIndex = tempRow.Item("physDiskIndex")
                .physDiskComment = tempRow.Item("physDiskComment")
                .physDiskLastUpdate = tempRow.Item("physDiskLastUpdate")
                .physDiskLastEdit = tempRow.Item("physDiskLastEdit")
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


    '
    ' for reading records
    '
    Public Sub moveDataRowToProperties _
                (ByVal tempRow As DataRow, _
                 ByRef tempDC As dc_DiskPhysical)

        Try

            With tempDC
                .initProperties()
                .physDiskKey = tempRow.Item("physDiskKey")
                .physDiskCompKey = tempRow.Item("physDiskCompKey")
                .physDiskDevIdDisk = tempRow.Item("physDiskDevIdDisk")
                .physDiskDevIdPartition = tempRow.Item("physDiskDevIdPartition")
                .physDiskBootable = tempRow.Item("physDiskBootable")
                .physDiskSize = tempRow.Item("physDiskSize")
                .physDiskBlockSize = tempRow.Item("physDiskBlockSize")
                .physDiskNumberOfBlocks = tempRow.Item("physDiskNumberOfBlocks")
                .physDiskIndex = tempRow.Item("physDiskIndex")
                .physDiskComment = tempRow.Item("physDiskComment")
                .physDiskLastUpdate = tempRow.Item("physDiskLastUpdate")
                .physDiskLastEdit = tempRow.Item("physDiskLastEdit")
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub moveDataTableToObservableCollection _
            (ByVal dtTemp As DataTable)

        Try

            If 0 < dtTemp.Rows.Count Then

                If m_oc IsNot Nothing Then
                    m_oc = Nothing
                    m_oc = New Collection(Of dc_DiskPhysical)
                Else
                    m_oc = New Collection(Of dc_DiskPhysical)
                End If

                Dim drTemp As DataRow
                Dim dcTemp As dc_DiskPhysical
                For Each drTemp In dtTemp.Rows
                    dcTemp = New dc_DiskPhysical
                    moveDataRowToProperties(drTemp, dcTemp)
                    m_oc.Add(dcTemp)
                Next

            End If

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub


    '
    '
    '
    Public Function moveDataTableToXML() As XmlDocument

        Dim writer = New System.IO.StringWriter
        Dim m_dt_xml As Xml.XmlDocument = Nothing

        Try


            m_dt.WriteXml(writer, XmlWriteMode.WriteSchema, True)
            m_dt_xml = Nothing
            m_dt_xml = New Xml.XmlDocument
            m_dt_xml.LoadXml(writer.ToString)

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally

            writer = Nothing

        End Try

        Return m_dt_xml


    End Function




#End Region

#Region " Standard Calls "


    '
    ' take the existing Table and put it back into the database
    ' with any changes that may have occured
    '
    Public Function dbUpdateDataSet() As Int16

        Dim rowsAffected As Int16 = 0

        Try

            rowsAffected = m_db.UpdateDataSet(m_ds, dc_racktables.tblattrdiskphysical.tostring, _
                                        m_insertCommand, _
                                        m_updateCommand, _
                                        m_deleteCommand, _
                                        UpdateBehavior.Standard)
            'msgbox rowsAffected

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        End Try

        Return rowsAffected

    End Function

    '
    '
    '
    Private Sub buildInsertAttrPhysDiskCommand()



        Try
            m_insertCommand = m_db.GetStoredProcCommand("insertAttrDiskPhysical")

            Dim cmdActive As DbCommand
            cmdActive = m_insertCommand

            m_db.AddInParameter(cmdActive, "physDiskCompKey", DbType.Int32, "physDiskCompKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskDevIdDisk", DbType.String, "physDiskDevIdDisk", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskDevIdPartition", DbType.String, "physDiskDevIdPartition", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskBootable", DbType.String, "physDiskBootable", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskBlockSize", DbType.Int16, "physDiskBlockSize", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskNumberOfBlocks", DbType.Int32, "physDiskNumberOfBlocks", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskIndex", DbType.Int16, "physDiskIndex", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskComment", DbType.String, "physDiskComment", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskLastUpdate", DbType.Date, "physDiskLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskLastEdit", DbType.String, "physDiskEdit", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Private Sub buildDeleteAttrPhysDiskCommand()

        Try
            m_deleteCommand = m_db.GetStoredProcCommand("deleteAttrDiskPhysical")

            Dim cmdActive As DbCommand
            cmdActive = m_deleteCommand

            m_db.AddInParameter(cmdActive, "physDiskKey", DbType.Int32, "physDiskKey", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try
    End Sub

    '
    '
    '
    Private Sub buildUpdateAttrPhysDiskCommand()


        Try
            m_updateCommand = m_db.GetStoredProcCommand("updateAttrDiskPhysical")

            Dim cmdActive As DbCommand
            cmdActive = m_updateCommand

            m_db.AddInParameter(cmdActive, "physDiskKey", DbType.Int32, "physDiskKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskCompKey", DbType.Int32, "physDiskCompKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskDeviceIdDisk", DbType.String, "physDiskDeviceIdDisk", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskDeviceIdPartition", DbType.String, "physDiskDeviceIdPartition", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskBootable", DbType.String, "physDiskBootable", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskBlockSize", DbType.Int16, "physDiskBlockSize", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskNumberOfBlocks", DbType.Int32, "physDiskNumberOfBlocks", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskIndex", DbType.Int16, "physDiskIndex", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskComment", DbType.String, "physDiskComment", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskLastUpdate", DbType.Date, "physDiskLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "physDiskLastEdit", DbType.String, "physDiskEdit", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub


    '
    ' create a record based on property values move it to the generic datatable
    ' then copy the table to the database
    '
    Public Function addAttrDiskPhysicalDataSourceRecord _
        (ByVal tempDC As dc_DiskPhysical, _
         Optional ByVal blnSilent As Boolean = False) _
        As Integer

        Dim intRowsAffected As Integer = 0

        Try

            initDataSetAndTable()

            Dim m_dr As DataRow = m_ds.Tables(dc_racktables.tblattrdiskphysical.tostring).NewRow
            movePropertiesToDataRow(m_dr, tempDC)
            m_ds.Tables(dc_racktables.tblattrdiskphysical.tostring).Rows.Add(m_dr)
            intRowsAffected = dbUpdateDataSet()


            If blnSilent = False Then
                MsgBox("DataRowsUpated = " & intRowsAffected)
            End If

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        Return intRowsAffected

    End Function


    '
    '
    '
    Public Sub initDataSetAndTable()

        Try

            ' make sure the root stuff is there
            If m_ds Is Nothing Then
                m_ds = New DataSet
            Else
                m_ds = Nothing
                m_ds = New DataSet
            End If
            m_ds.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema

            If m_dt Is Nothing Then
                m_dt = New DataTable
            Else
                m_dt = Nothing
                m_dt = New DataTable
            End If


            If m_oc Is Nothing Then
                m_oc = New Collection(Of dc_DiskPhysical)
            Else
                m_oc = Nothing
                m_oc = New Collection(Of dc_DiskPhysical)
            End If

            If m_dc Is Nothing Then
                m_dc = New dc_DiskPhysical(strUserId)
            Else
                m_dc = Nothing
                m_dc = New dc_DiskPhysical(strUserId)
            End If

            CreateTableColumns(m_dt)
            m_dt.TableName = dc_racktables.tblattrdiskphysical.tostring
            m_ds.Tables.Add(m_dt)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub




#End Region

#Region " database calls "



    '
    '
    '
    Public Sub dbSelectAllDiskPhysical()


        Try



            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand(readAll)
            m_db.LoadDataSet(cmd, m_ds, dc_racktables.tblattrdiskphysical.tostring)

            m_dt = m_ds.Tables(dc_racktables.tblattrdiskphysical.tostring)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub dbSelectAttrDiskPhysicalByCompKey(ByVal intCompKey As Int32)


        Try


            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectAttrDiskPhysicalByCompKey")
            m_db.AddInParameter(cmd, "@compKey", DbType.Int32, intCompKey)
            m_db.LoadDataSet(cmd, m_ds, dc_racktables.tblattrdiskphysical.tostring)

            m_dt = m_ds.Tables(dc_racktables.tblattrdiskphysical.tostring)

            If m_dt.Rows.Count = 1 Then
                Dim m_dr As System.Data.DataRow = m_dt.Rows(0)
                moveDataRowToProperties(m_dr)
            End If


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub dbSelectAttrDiskPhysicalByRowKey _
            (ByVal lngRowKey As Int32)

        Try

            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectAttrDiskPhysicalByRowKey")
            m_db.AddInParameter(cmd, "@RowKey", DbType.Int32, lngRowKey)
            m_db.LoadDataSet(cmd, m_ds, dc_racktables.tblattrdiskphysical.tostring)
            m_dt = m_ds.Tables(dc_racktables.tblattrdiskphysical.tostring)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub dbSelectAttrDiskPhysicalByUrriKeys _
            (ByVal colURRIKeys As Collection(Of clsDC_RackData.rackURRI))

        initDataSetAndTable()


        Dim dtInput As DataTable = New DataTable
        Dim dtOutput As DataTable = New DataTable
        Dim drTemp As DataRow
        Dim lngRackKey As Int32
        Dim colRacks As Collection = New Collection
        Dim rckUrri As clsDC_RackData.rackURRI

        For Each rckURRI In colURRIKeys
            colRacks.Add(rckUrri.rckKey)
        Next rckURRI

        Try

            For intX = 1 To colRacks.Count
                lngRackKey = colRacks(intX)
                If Not (dtInput Is Nothing) Then
                    dtInput = Nothing
                    dtInput = New DataTable
                Else
                    dtInput = New DataTable
                End If
                dtInput = GetAttrDiskPhysicalByRack(lngRackKey)
                With dtInput
                    If intX = 1 Then
                        dtOutput = Nothing
                        dtOutput = New DataTable
                        dtOutput = dtInput.Copy
                    Else
                        For Each drTemp In .Rows
                            dtOutput.ImportRow(drTemp)
                        Next
                    End If
                End With
            Next intX

            For Each drTemp In dtOutput.Rows
                m_ds.Tables(DC_RackTables.tblAttrDiskPhysical.ToString).ImportRow(drTemp)
            Next

            m_dt = m_ds.Tables(DC_RackTables.tblAttrDiskPhysical.ToString)
            m_dt.TableName = DC_RackTables.tblAttrDiskPhysical.ToString

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Function GetAttrDiskPhysicalByRack _
                (ByVal lngRackKey As Int32) _
                As DataTable

        Dim m_dt1 As DataTable = New DataTable
        Dim dtReturn As DataTable = New DataTable
        Dim m_ds1 As DataSet = New DataSet

        Try

            Dim cmd1 As DbCommand
            cmd1 = m_db.GetStoredProcCommand("selectAttrDiskPhysicalByRack")
            m_db.AddInParameter(cmd1, "@compKey", DbType.Int32, lngRackKey)
            m_db.LoadDataSet(cmd1, m_ds1, "temp")
            m_dt1 = m_ds1.Tables("temp")

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
            m_dt1 = Nothing
        End Try

        GetAttrDiskPhysicalByRack = m_dt1

    End Function


#End Region

#Region " Constructor "



    '
    '
    '
    Public Sub New(ByVal visApp As Microsoft.Office.Interop.Visio.Application, _
                    ByVal visDoc As Microsoft.Office.Interop.Visio.Document)
        Try


            m_db = DatabaseFactory.CreateDatabase()

            strUserId = Environment.UserDomainName & "/" & Environment.UserName

            '
            ' init an object class so that the default constants are available
            ' to the table definitions
            '

            If m_dc IsNot Nothing Then
                m_dc = Nothing
                m_dc = New dc_DiskPhysical(strUserId)
            Else
                m_dc = New dc_DiskPhysical(strUserId)
            End If

            initDataSetAndTable()


            _clsVisio = New visRackComponentAttributes.clsVisioSupport
            _clsVisio.drawingApplication = visApp
            _clsVisio.drawingDocument = visDoc

            m_updateCommand = Nothing
            m_insertCommand = Nothing
            m_deleteCommand = Nothing

            buildInsertAttrPhysDiskCommand()
            buildDeleteAttrPhysDiskCommand()
            buildUpdateAttrPhysDiskCommand()


        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


#End Region

#Region " Visio Properties "

    '
    '
    '
    Public Sub UpdateDiskPhyscialProperties _
        (ByRef visShape As Microsoft.Office.Interop.Visio.Shape, _
         ByVal drDiskP As System.Data.DataRow)



        Try
            With m_dc

                If Not (drDiskP Is Nothing) Then

                    moveDataRowToProperties(drDiskP)

                End If


                _clsVisio.ForceShapeData(visShape, "physDiskKey", CStr(.physDiskKey), "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskCompKey", CStr(.physDiskCompKey), "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskDevIdDisk", .physDiskDevIdDisk, "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskDevIdPartition", .physDiskDevIdPartition, "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskBootable", .physDiskBootable, "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskSize", CStr(.physDiskSize), "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskBlockSize", CStr(.physDiskBlockSize), "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskNumberOfBlocks", CStr(.physDiskNumberOfBlocks), "attrDiskP")
                _clsVisio.ForceShapeData(visShape, "physDiskIndex", CStr(.physDiskIndex), "attrDiskP")

            End With


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    Private Const constDiskPPinX As String = "4 in"
    Private Const constDiskPPinY As String = "8 in"
    Private Const constDiskPAlign As VisListAlignment = VisListAlignment.visListAlignLeftOrTop
    Private Const constDiskPDir As VisListDirection = VisListDirection.visListDirTopToBottom
    Private Const constDiskPHeader As String = "Physical Disks"
    Private Const constDiskPMaster As String = "Container 4"

    '
    '
    '
    Public Function buildComponentDiskPhysicalContainer _
                        (ByVal intCompKey As Int32, _
                       ByVal _clsData As clsDC_RackData) _
                        As Microsoft.Office.Interop.Visio.Shape

        Dim shpContainer As Microsoft.Office.Interop.Visio.Shape = Nothing

        ' just to make sure
        _clsVisio.drawingPage = drawingPage
        drawingDocument = drawingPage.Document

        Try



            Dim colInput As Collection = New Collection
            Dim drTemp As System.Data.DataRow = Nothing
            Dim diskpQuery = From diskphysical In _clsData.m_ds.Tables(DC_RackTables.tblAttrDiskPhysical.ToString).AsEnumerable() _
                       Where diskphysical!physdiskCompKey = intCompKey
                      Select diskphysical

            If diskpQuery.Count = 0 Then Return shpContainer

            For Each dp In diskpQuery
                colInput.Add("physDiskKey_" & dp.Item("physDiskKey").ToString)
                'System.Diagnostics.Debug.WriteLine(dp.Item("physDiskDevIdDisk").ToString)
                'System.Diagnostics.Debug.WriteLine(dp.Item("physDiskKey").ToString)
            Next dp

            ' create a list control
            Dim listControl As Microsoft.Office.Interop.Visio.Shape = Nothing
            Dim colMembers As Collection = New Collection

            Dim strStencil As String = ""
            Dim strMaster As String = ""
            Dim strDGMaster As String = ""
            Dim visDG As Microsoft.Office.Interop.Visio.Master = Nothing
            Dim intLabelFont As Integer
            Dim intValueFont As Integer
            Dim dblCalloutWidth As Double
            Dim dgmasterQuery = From datagraphic In _clsData.m_ds.Tables(DC_RackTables.tblDGMasters.ToString).AsEnumerable() _
                                Where datagraphic!dgmTable = DC_RackTables.tblAttrDiskPhysical.ToString _
                                Select datagraphic

            ' should only be one..
            For Each m In dgmasterQuery
                If LCase(m!dgmTable) = LCase(DC_RackTables.tblAttrDiskPhysical.ToString) Then
                    strStencil = m!dgmSurrogateStencil
                    strStencil = _CustomStencilPath & strStencil
                    strMaster = m!dgmSurrogateMaster
                    intLabelFont = CInt(m!dgmFontLabel)
                    intValueFont = CInt(m!dgmFontValue)
                    dblCalloutWidth = CDbl(m!dgmCalloutWidth)
                    strDGMaster = m!dgmMaster
                    Exit For
                End If
            Next

            ' pass in the created collection and return a populated list control
            colMembers = _clsVisio.dropDropDownBoxItems(colInput, strMaster, strStencil, "1.5in", "1in", vbTrue)

            Dim visShape As Microsoft.Office.Interop.Visio.Shape = Nothing
            Dim visCell As Microsoft.Office.Interop.Visio.Cell = Nothing
            Dim strName As String = ""
            Dim strKey As String = ""
            For Each shapeId In colMembers
                ' get the shape
                visShape = drawingPage.Shapes.ItemFromID(shapeId)

                If visShape.CellExists("user.attrkey", False) = True Then
                    strName = visShape.Cells("user.attrkey").ResultStr("")
                Else
                    strName = ""
                    GoTo NextShape
                End If

                ' clear any shape data properties
                _clsVisio.deleteShapeData(visShape)

                ' set it semi-transparent
                Dim strTrans As String = "50%"
                ' first the fill properties
                _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowFill, VisCellIndices.visFillForegndTrans, strTrans)
                _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowFill, VisCellIndices.visFillBkgndTrans, strTrans)
                ' then the line properties
                _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowLine, VisCellIndices.visLineColorTrans, strTrans)
                ' prep it for applying the datagraphics by applying the data from the dgmasters table
                _clsVisio.addDataGraphicUserFieldsToShape _
                        (visShape, _
                        intValueFont.ToString, _
                        intLabelFont.ToString, _
                        dblCalloutWidth.ToString)

                'Check that the requested Data Graphic Master exits
                For Each visMaster In drawingDocument.Masters
                    If visMaster.Type = VisMasterTypes.visTypeDataGraphic Then
                        If visMaster.Name = strDGMaster Then
                            visDG = visMaster
                            Exit For
                        End If
                    End If
                Next


                ' go read the current records
                For Each dp In diskpQuery
                    strKey = "physDiskKey_" & dp.Item("physDiskKey").ToString
                    If strKey = strName Then
                        UpdateDiskPhyscialProperties(visShape, dp)
                        visShape.Text = dp.Item("physDiskDevIdDisk").ToString

                        ' allow the legend to keep track of the shapes
                        _clsVisio.ForceUserProperty(visShape, "visLegendShape", "2.0")

                        ' move the name to comment field so we get mouse over
                        If visShape.CellsSRCExists(VisSectionIndices.visSectionObject, VisRowIndices.visRowMisc, VisCellIndices.visComment, False) = True Then
                            visCell = visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowMisc, VisCellIndices.visComment)
                            _clsVisio.SetCellValueToString(visCell, strName)
                        End If

                        'Apply the Data Graphic to the Shape
                        visShape.DataGraphic = visDG

                        ' unlock the groups so we can change the font sizes
                        _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowLock, VisCellIndices.visLockGroup, "0")

                        If visShape.CellExists("user.dbIntLabelFont", False) = True Then

                            ' get the loaded values 
                            intLabelFont = CInt(visShape.Cells("user.dbintlabelfont").ResultIU)
                            intValueFont = CInt(visShape.Cells("user.dbintvaluefont").ResultIU)
                            dblCalloutWidth = CDbl(visShape.Cells("user.dbdblcallout").ResultIU)

                            ' set the callout width = 85% of the surrogate shapes width (as a formula) so that it fits inside the shape
                            Dim strId As String = visShape.NameID & "!Width*.85"
                            strId = "Guard(" & strId & ")"

                            _clsVisio.recurseApplyCustomFormula(visShape, "prop.msvcalloutproplabelsize", intLabelFont.ToString & " pt")
                            _clsVisio.recurseApplyCustomFormula(visShape, "prop.msvcalloutpropvaluesize", intValueFont.ToString & " pt")
                            _clsVisio.recurseApplyCustomFormula(visShape, "prop.msvcalloutpropwidth", strId)

                        End If

                        Exit For
                    End If
                Next dp
NextShape:
            Next shapeId


            shpContainer = _clsVisio.addContainerToPage(constDiskPMaster, "contPhysicalDisk", "")

            listControl = _clsVisio.loadListControl(colMembers, constDiskPAlign, constDiskPDir)
            listControl.Name = "listDiskP"
            listControl.NameU = "listDiksP"


            ' add the list control to the container
            _clsVisio.AddShapeToContainer(shpContainer, listControl)

            shpContainer.Cells("pinx").Formula = constDiskPPinX
            shpContainer.Cells("piny").Formula = constDiskPPinY



        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try
        System.Windows.Forms.Application.DoEvents()
        Return shpContainer

    End Function



#End Region


End Class
